﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Compiler
{
    public static class Tools
    {
        public static void Print<U, T>(this U collection) where U : IEnumerable<T>
        {
            bool first = true;
            foreach (var item in collection)
            {
                if (!first)
                    Console.Write(", ");
                first = false;
                Console.Write(item);
            }
        }

        public static string ListToString<T>(List<T> list)
        {
            StringBuilder b = new StringBuilder();
            foreach (var item in list)
                b.Append(item.ToString() + ", ");
            return b.ToString();
        }

        public static string ArrayToString<T>(T[] list)
        {
            StringBuilder b = new StringBuilder();
            foreach (var item in list)
                b.Append(item.ToString() + ", ");
            return b.ToString();
        }

        public static string HashSetPrinter<T>(HashSet<T> set)
        {
            if (set.Count == 0)
                return "{}";

            StringBuilder b = new StringBuilder();
            b.Append("{ ");
            foreach (var item in set)
            {
                b.Append(item.ToString());
                b.Append(" , ");
                //b.Append(" ,\n ");
            }
            b.Remove(b.Length - 3, 3);
            b.Append(" }");

            return b.ToString();
        }
    }
}
